package com.example.areaclean;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.example.areaclean.dao.User;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class manager_activity extends AppCompatActivity {
    private SharedPreferences pref;
    private SharedPreferences.Editor editor;
    RequestQueue queue;
    private TextView textView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_manager);


        Button man_area =findViewById(R.id.btn_man_area);
        textView=findViewById(R.id.text_man);


        queue = Volley.newRequestQueue(getApplicationContext());
        pref = getSharedPreferences("data",MODE_PRIVATE);
        jsonRequest(pref.getString("userNo"," "));

        man_area.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(manager_activity.this,man_area_activity.class);
                startActivity(intent);
            }
        });
    }
    public void jsonRequest(String s_no){
        String url= "http://192.168.31.32/tp/public/index.php/api/getName";
        HashMap<String, String> params = new HashMap<>();
        params.put("s_no",s_no);
        JSONObject jsonObject = new JSONObject(params);

        final JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.POST, url, jsonObject,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject jsonObject) {
                        String a="";
                        try {
                            a = jsonObject.getString("s_name");
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        textView.setText(a);

                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        Log.d("TAG","fuckError"+volleyError);
                    }
                });
        queue.add(jsObjRequest);


    }


}
